<?php

namespace App\Http\Middleware;

use Closure;

class AdminLogin
{
    /**
     * Handle an incoming request.
     *
     * @param  \Illuminate\Http\Request  $request
     * @param  \Closure  $next
     * @param  string|null  $guard
     * @return mixed
     */
    public function handle($request, Closure $next, $guard = null)
    {
        // session(['admin_id'=>null]);
        $admin_id = session('admin_id');

        // echo '访问该页面之前，访问到了中间键<br>';    redirect是‘重定向’的意思
        if(!isset($admin_id)){
            return redirect('houtai/login');
        }

        echo '登录成功，用户ID为：' . $admin_id . '<br>';

        return $next($request);
    }
}
